From 68332b5be771427339d2373d1e3a22681685c832 Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Mon, 1 Nov 2021 00:49:57 -0500 Subject: [PATCH] C++ improvements in VCard. Add tests. (#750) * C++ improvements inside Vcard. Add test. * Eternal impedance mismatch on C vs C++ pointer ownership. * VCF: Incorporate review feedback: auote ','. Match HTML tage regardless of case. * Quote commas in ASCII source, not just UTH8-encoded text. --- reference/gc/GCGCA8~vcard.vcf | 7 +++++++ testo.d/vcard.test | 5 +++++ vcf.cc | 28 +++++++++++++++------------- 3 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 reference/gc/GCGCA8~vcard.vcf create mode 100644 testo.d/vcard.test diff --git a/reference/gc/GCGCA8~vcard.vcf b/reference/gc/GCGCA8~vcard.vcf new file mode 100644 index 000000000..cb0aaf5b0 --- /dev/null +++ b/reference/gc/GCGCA8~vcard.vcf @@ -0,0 +1,7 @@ +BEGIN:VCARD +VERSION:3.0 +N:Oozy rat in a sanitary zoo;GCGCA8;;; +ADR:N35 55.300 W86 51.700 +URL:http://www.geocaching.com/seek/cache_details.aspx?guid=cda94cd6-d657-49bd-8e7e-0031ef1b2613 +NOTE:The cache is not at the coordinates above. These coords will get you to the correct park and within 1/2 mile of the cache. The cache is within 35 feet of the trail. It is not handicapped accessible. It is a nice walk in the woods that is practical for all ages. There is no space in the container for trading items. You should bring a writing stick and bug spray is recommended.\nSo if the cache isn't at the above coordinates\, where is it? Too bad I hid a boot Too hot to hoot Never odd or even Do geese see God? "Do nine men interpret?" "Nine men\," I nod Rats live on no evil star Go hang a salami\, I'm a lasagna hog Now that it's intuitively obvious to even the most casual observer where the cache is\, turn on your geo-mojo and go find it. \n [IMG]\n\nHINT:\nThere Is No Hint +END:VCARD diff --git a/testo.d/vcard.test b/testo.d/vcard.test new file mode 100644 index 000000000..188ce7b58 --- /dev/null +++ b/testo.d/vcard.test @@ -0,0 +1,5 @@ +rm -f ${TMPDIR}/GCGCA8.vcf + +gpsbabel -i gpx -f ${REFERENCE}/gc/GCGCA8.gpx -o vcard -F ${TMPDIR}/GCGCA8.vcf +compare ${TMPDIR}/GCGCA8.vcf ${REFERENCE}/gc/GCGCA8~vcard.vcf + diff --git a/vcf.cc b/vcf.cc index da94b2c65..d5dc31d96 100644 --- a/vcf.cc +++ b/vcf.cc @@ -64,15 +64,16 @@ vcf_print_utf(const utf_string* s) return; } - char* stripped_html = strip_html(s); - char* p = gstrsub(stripped_html, "\n", "\\n"); - char* p2 = gstrsub(p, "

", "\\n"); - char* p3 = gstrsub(p2, ";", "\\;"); - gbfputs(p3, file_out); - xfree(p); - xfree(p2); - xfree(p3); - xfree(stripped_html); + char *string = strip_html(s); + QString stripped_html = string; + xfree(string); + + stripped_html.replace("\n", "\\n", Qt::CaseInsensitive); + stripped_html.replace("

", "\\n", Qt::CaseInsensitive); + stripped_html.replace(";", "\\;"); + stripped_html.replace(",", "\\,"); + + gbfputs(stripped_html, file_out); } static void @@ -82,9 +83,10 @@ vcf_print(const char* s) return; } - char* p = gstrsub(s, "\n", "\\n"); - gbfputs(p, file_out); - xfree(p); + QString cleaned = s; + cleaned.replace("\n", "\\n", Qt::CaseInsensitive); + cleaned.replace(",", "\\,"); + gbfputs(cleaned, file_out); } static void @@ -117,7 +119,7 @@ vcf_disp(const Waypoint* wpt) QString s = rot13(wpt->gc_data->hint); vcf_print(s); } else { - vcf_print(CSTR(wpt->gc_data->hint)); + vcf_print(wpt->gc_data->hint); } gbfprintf(file_out, "\nEND:VCARD\n"); -- 2.30.2